﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Input;
using XNAGuiLib.GuiLibButtons;
using XNAGuiLib.GuiLibAction;
using Microsoft.Xna.Framework;

namespace XNAGuiLib
{
    /// <summary>
    /// Class to provide static methods for generating ActionObjects for Key or MouseInput
    /// </summary>
    public class ActionFactory
    {
        
        // Method to generate a Action Object for MouseInput
        #region Static Method - MouseAction(InterfaceObject target, TextureObject textureInvoker, TextObject textInvoker, Action.Invoker invoker, Action.CommandType type, MouseAction.Inputs input, MouseAction.MouseButtons mouseButton,  string command, Action.KeyModifiers keyModifier)
        /// <summary>
        /// Generates a ActionObject for MouseInput
        /// </summary>
        /// <param name="target">the interfaceObject on which the command will be executed</param>
        /// <param name="textureInvoker">---</param>
        /// <param name="textInvoker">---</param>
        /// <param name="invoker">---</param>
        /// <param name="type">what command type (predefined or Custom)</param>
        /// <param name="input">which input to use (Down, Pressed, Released)</param>
        /// <param name="mouseButton">which mouseButton to check on this Action</param>
        /// <param name="command">user definded command to be executed (or tried to ^^)</param>
        /// <param name="keyModifier">key modification (ctrl, ctrl+alt, ctrl+alt+shift, alt, alt+shift, shift</param>
        /// <returns></returns>
        public static Action MouseAction(InterfaceObject target, 
                                        TextureObject textureInvoker,
                                        TextObject textInvoker,
                                        Action.Invoker invoker,
                                        Action.CommandType type,
                                        MouseAction.Inputs input,
                                        MouseAction.MouseButtons mouseButton, 
                                        string command,
                                        Action.KeyModifiers keyModifier)
        {
            MouseAction action = new MouseAction();
            action.Target = target;
            action.InvokerTexture = textureInvoker;
            action.InvokerText = textInvoker;
            action.InvokerType = invoker;
            action.Type = type;
            action.Input = input;
            action.Device = Action.Devices.Mouse;
            action.MouseButton = mouseButton;
            action.Command = command;
            action.KeyModifier = keyModifier;

            return action;
        }
        #endregion
        
        // Method to generate a Action Object for KeyboardInput
        #region Static Method - KeyAction(InterfaceObject target, TextureObject textureInvoker, TextObject textInvoker, Action.Invoker invoker, Action.CommandType type, KeyAction.Inputs input, Keys[] keys, string command, Action.KeyModifiers keyModifier)
        /// <summary>
        /// Generates a ActionObject for KeyboardInput
        /// </summary>
        /// <param name="target">the interfaceObject on which the command will be executed</param>
        /// <param name="textureInvoker">---</param>
        /// <param name="textInvoker">---</param>
        /// <param name="invoker">---</param>
        /// <param name="type">what command type (predefined or Custom)</param>
        /// <param name="input">which input to use (Down, Pressed, Released)</param>
        /// <param name="keys">keys to use on the action</param>
        /// <param name="command">user definded command to be executed (or tried to ^^)</param>
        /// <param name="keyModifier">key modification (ctrl, ctrl+alt, ctrl+alt+shift, alt, alt+shift, shift</param>
        /// <returns></returns>
        public static Action KeyAction(InterfaceObject target,
                                       TextureObject textureInvoker,
                                       TextObject textInvoker,
                                       Action.Invoker invoker,
                                       Action.CommandType type,
                                       KeyAction.Inputs input,
                                       Keys[] keys,
                                       string command,
                                       Action.KeyModifiers keyModifier)
        {
            KeyAction action = new KeyAction();
            action.Target = target;
            action.InvokerTexture = textureInvoker;
            action.InvokerText = textInvoker;
            action.InvokerType = invoker;
            action.Type = type;
            action.Input = input;
            action.Device = Action.Devices.Keyboard;
            action.KeyList.AddRange(keys);
            action.Command = command;
            action.KeyModifier = keyModifier;

            return action;
        }
        #endregion

        // Method to generate a Action Object for MouseInput (used on ButtonObjects)
        #region Static Method - ButtonAction(InterfaceObject target, ButtonObject button, MouseAction.Inputs input, MouseAction.MouseButtons mouseButton, Action.KeyModifiers keyModifier, string command)
        /// <summary>
        /// Generates a ActionObject for MouseInput (used on a ButtonObject)
        /// </summary>
        /// <param name="target">the interfaceObject on which the command will be executed</param>
        /// <param name="button">the Button on which the Action whould be installed</param>
        /// <param name="input">which input to use (Down, Pressed, Released)</param>
        /// <param name="mouseButton">which button (Left, Middle, Right)</param>
        /// <param name="keyModifier">key modification (ctrl, ctrl+alt, ctrl+alt+shift, alt, alt+shift, shift</param>
        /// <param name="command">user definded command to be executed (or tried to ^^)</param>
        /// <returns></returns>
        public static Action ButtonAction(InterfaceObject target, 
                                            ButtonObject button, 
                                            MouseAction.Inputs input,
                                            MouseAction.MouseButtons mouseButton, 
                                            Action.KeyModifiers keyModifier, 
                                            string command)
        {
            MouseAction action = new MouseAction();
            action.Target = target;
            action.InvokerTexture = button.Clicked;
            action.InvokerText = button.TextObj;
            action.InvokerType = Action.Invoker.Texture;
            action.Type = Action.CommandType.Custom;
            action.Input = input;
            action.Device = Action.Devices.Mouse;
            action.MouseButton = mouseButton;
            action.Command = command;
            action.KeyModifier = keyModifier;

            return action;
        }
        #endregion

        // Method to generate a Action Object for MouseInput (used on InterfaceObjects)
        #region Static Method - InterfaceObjectAction(InterfaceObject target, InterfaceObject inv, Action.CommandType type, MouseAction.Inputs input, MouseAction.MouseButtons mouseButton, string command, Action.KeyModifiers keyModifier)
        /// <summary>
        /// Generates a ActionObject for MouseInput
        /// </summary>
        /// <param name="target">the interfaceObject on which the command will be executed</param>
        /// <param name="inv">invoker which will be checked against mouse position</param>
        /// <param name="type">what command type (predefined or Custom)</param>
        /// <param name="input">which input to use (Down, Pressed, Released)</param>
        /// <param name="mouseButton">which mouseButton to check on this Action</param>
        /// <param name="command">user definded command to be executed (or tried to ^^)</param>
        /// <param name="keyModifier">key modification (ctrl, ctrl+alt, ctrl+alt+shift, alt, alt+shift, shift</param>
        /// <returns></returns>
        public static Action InterfaceObjectAction(InterfaceObject target,
                                        InterfaceObject inv,
                                        Action.CommandType type,
                                        MouseAction.Inputs input,
                                        MouseAction.MouseButtons mouseButton,
                                        string command,
                                        Action.KeyModifiers keyModifier)
        {
            MouseAction action = new MouseAction();
            action.Target = target;
            action.InvokerInterfaceObject = inv;
            action.InvokerType = Action.Invoker.InterfaceObject;
            action.Type = type;
            action.Input = input;
            action.Device = Action.Devices.Mouse;
            action.MouseButton = mouseButton;
            action.Command = command;
            action.KeyModifier = keyModifier;

            return action;
        }
        #endregion

    }
}